package com.hjh.pro.exportdb.util;

import jdk.internal.dynalink.beans.StaticClass;

import java.lang.reflect.Field;

public class ToolUtils {

    /**
     * 左边补0
     * @param iLen
     * @param iCode
     * @return
     */
    public static  String format(int iLen ,int iCode){
        String format = "%0"+iLen+"d";
        return  String.format(format,iCode);

    }

    /**
     * 获取Bean字段的值
     * @param bean
     * @param fieldName
     * @param <T>
     * @return
     */
    public static <T> Object getFieldValue(T bean,String fieldName){

        try {
            Field field=bean.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);

            return field.get(bean);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String ff = format(4,20);
        System.out.println("ff:" +ff);

        Result tt = new Result();

        tt.setCode(1);

        Object code = getFieldValue(tt,"code");
        System.out.println("========>>"+code);

    }
}
